<?php
define('MINI_RUN', true);
require 'mini.php';
if (empty($_GET['pageid'])) exit("非法操作！");
Mini::checkLogin();
$pdo = new MySQLPDO();
$select = 'SELECT pageid,title,classid,keyword,`desc`,source,author,smalltext,content,filename FROM Mini_Page WHERE PageId = ? limit 1';
$paramArray = array($_GET['pageid']);
$pageArray = $pdo->selectSQL($select,$paramArray);
if (!$page = $pageArray[0])
	exit("参数错误！");
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content = "text/html; charset=utf-8" />
<title>添加文章--<?=Mini::NAME?>后台管理系统</title>
<?=Mini::ADMIN_CSS?>
</head>
<body>
<p class = "msg">&nbsp;</p>
<form id = "pageform" method = "post" >
<input id = "pageid" type = "hidden" value = "<?php echo $page['pageid']?>" />
<input id = "oldname" type = "hidden" value = "<?php echo $page['filename'];?>"/>
文件名*：<input id = "filename" type = "text" value = "<?php echo $page['filename']?>" />.html<br /><br />
栏目名称*：
<input id = "oldid" type = "hidden" value = "<?php echo $page['classid']?>" />
<select id = "classid">
<?=Mini::getsubclass()?>
</select><br /><br />
<br />
文章标题*：<input id = "title" type = "text" size = "60" value = "<?php echo $page['title']?>" /><br /><br />
关键字*：<input id = "keyword" type = "text" value = "<?php echo $page['keyword']?>" /><br /><br />
描述*： <input id = "desc" type = "text" value = "<?php echo $page['desc']?>" /><br /><br />
来源*： <input id = "source" type = "text" value = "<?php echo $page['source']?>"/><br /><br />
作者*：<input id = "author" type = "text" value = "<?php echo $page['author'];?>" /><br /><br />
本文相关链接内容(可为空)：<br /><textarea id = "smalltext" rows = "10" cols = "100" ><?php echo $page['smalltext'];?></textarea><br />
正文内容*：<br /><textarea id = "content" rows = "20" cols = "100"><?php echo $page['content'];?></textarea><br /><br />
<input id = "savebtn" type = "button" value = "修改" />
</form>
<?=Mini::JQUERY_JS?>
<script type = "text/javascript">
var noPass = true;
$(function(){
	$("select option[value = '<?php echo $page['classid']?>']").attr("selected","selected");
	$("#filename").blur(checkExists);
	$("#classid").change(checkExists);
	$("#savebtn").click(function(){		
	if(checkNull("#filename","文件名")){
		return;			
	}else if(checkNull("#title","文章标题")){
		return;
	}else if(checkNull("#keyword","关键字")){
		return;
	}else if(checkNull("#desc","描述内容")){
		return;
	}else if(checkNull("#source","来源")){
		return;
	}else if(checkNull("#author","作者")){
		return;
	}else if(checkNull("#content","文章内容")){
		return;
	}else{
		if($.trim($("#smalltext").val()) == ""){
			if(!confirm("相关链接内容确定为空？"))
				return;
		}			
		$.post(<?=Mini::AJAX_SET?>,{op:"setpage",pageid:$("#pageid").val(),title:$("#title").val(),classid:$("#classid").val(),filename:$("#filename").val(),keyword:$("#keyword").val()
			,desc:$("#desc").val(),source:$("#source").val(),author:$("#author").val(),smalltext:$("#smalltext").val(),content:$("#content").val()},function(result){
				if(result == "OK"){
					alert("修改文章成功！");
					$(".msg").html("修改成功！");
				}else{
					alert("修改文章失败！");
					$(".msg").html("修改文章失败！可能是网络原因或参数异常！");
				}
			});
	}
	});
});
function checkExists(){	
	var filename = $.trim($("#filename").val());
	if(filename != ""){
	var reg = /^[-a-z\d_]+$/;
	if(!reg.test(filename)){
		alert("文件名不符合规则！");
		$(".msg").html("文件名不符合规则(小写字母、数字、-、_)");
		$("#filename").val("");
		return;
	}
	if($("#classid").val() == $("#oldid").val()&&$("#filename").val() == $("#oldname").val())
		return;
	var	optionname = "AND ClassId = "+$("#classid").val();	
	$.post(<?=Mini::AJAX_GET?>,{op:"checkexists",table:"Mini_Page",column:"filename",value:filename,options:optionname},function(result){
		if(result == "OK"){			
			noPass = true;
			alert("文件名已存在！");
			$(".msg").html("文件名 "+filename+" 在当前栏目中已存在！");
			$("#filename").val($("#oldname").val());
		}else{
			noPass = false;			
		}
	});
	}
}
function checkNull(idname,tips){
	if($.trim($(idname).val()) == ""){
		alert(tips+"不能为空！");
		$(".msg").html(tips+"不能为空！");
		$(idname).focus();
		noPass = true;
	}else{
		noPass = false;
	}
	return noPass;
}
</script>
</body>
</html>